#ifndef _BLOCKBREAKER_COMM_CHANNEL_H__
#define _BLOCKBREAKER_COMM_CHANNEL_H__

#include <Comm/Include/SyncQueue.h>
#include <Comm/Include/TCPSocket.h>

typedef enum
{
    SENDING_CLOSED,
    RECEPTION_CLOSED,
    RECEPTION_TIMEOUT,
    CONNECTION_FAILED
}ChannelExceptionType;

class Channel
{
    friend class AdmComm;

    public:
        void send(SimpleMessage* msg);

        SimpleMessage* receive(unsigned int timeout = 0);

        void installAsyncReceiveFunction(TCallbackAsyncReceiveFunction f, void* user_data);

        void* uninstallAsyncReceiveFunction();

        void terminateSending();

        void terminateReceiving();

    private:
        TCPSocket* ipc_resource;

        Semaphore* sem_sync_canal_tx_rx_tasks;

        SyncQueue* RxQueue;

        SyncQueue* TxQueue;

        bool sending_closed;

        bool receiving_closed;

        Channel(SyncQueue* _Tx_Queue, SyncQueue* _Rx_Queue, TCPSocket* ipc_resource, Semaphore* _sem_sync_canal_tx_rx_tasks);
        
        virtual ~Channel(void);
        
        SyncQueue* getRxQueue();
        
        SyncQueue* getTxQueue();

        void terminate();
};
#endif // _BLOCKBREAKER_COMM_CHANNEL_H__
